{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 导入所需的第三方库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import numpy as np \n",
    "import re\n",
    "import pymongo\n",
    "\n",
    "from pyecharts.charts import Pie, Bar, Map, WordCloud,Line,Grid,Scatter,Radar,Page \n",
    "from pyecharts import options as opts\n",
    "from pyecharts.globals import SymbolType\n",
    "from pyecharts.globals import ThemeType"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 连接mongodb数据库读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "client = pymongo.MongoClient('localhost', 27017)\n",
    "db = client['data']\n",
    "job_data = db['info']\n",
    "data = pd.DataFrame(list(job_data.find()))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 预览数据集前五行信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>_id</th>\n",
       "      <th>职位名称</th>\n",
       "      <th>公司名称</th>\n",
       "      <th>工作城市</th>\n",
       "      <th>薪资范围</th>\n",
       "      <th>学历要求</th>\n",
       "      <th>公司类型</th>\n",
       "      <th>公司规模</th>\n",
       "      <th>职位类别</th>\n",
       "      <th>工作经验</th>\n",
       "      <th>福利待遇</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>5fe143d01766012a7d73fa28</td>\n",
       "      <td>在家作业/网上兼职/线上操作</td>\n",
       "      <td>中环汇峰环境科技(北京)有限公司</td>\n",
       "      <td>北京</td>\n",
       "      <td>8千-1万</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>其它</td>\n",
       "      <td>20人以下</td>\n",
       "      <td>技工/操作工</td>\n",
       "      <td>不限</td>\n",
       "      <td>五险一金,加班补助,全勤奖,绩效奖金</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>5fe143d01766012a7d73fa2b</td>\n",
       "      <td>送货司机</td>\n",
       "      <td>中融永信(北京)投资管理有限公司</td>\n",
       "      <td>北京</td>\n",
       "      <td>4千-6千</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>其它</td>\n",
       "      <td>500-999人</td>\n",
       "      <td>技工/操作工</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>包吃,包住,节日福利,带薪年假,上六休一</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>5fe143d01766012a7d73fa2e</td>\n",
       "      <td>警卫</td>\n",
       "      <td>美国驻华大使馆</td>\n",
       "      <td>北京</td>\n",
       "      <td>6千-8千</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>国家机关</td>\n",
       "      <td>100-299人</td>\n",
       "      <td>行政/后勤/文秘</td>\n",
       "      <td>1年以下</td>\n",
       "      <td>五险一金,加班补助,带薪年假</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>5fe143d01766012a7d73fa31</td>\n",
       "      <td>Bodyguard</td>\n",
       "      <td>美国驻华大使馆</td>\n",
       "      <td>北京</td>\n",
       "      <td>8千-1万</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>国家机关</td>\n",
       "      <td>100-299人</td>\n",
       "      <td>社区/居民/家政服务</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>五险一金,带薪年假,年底双薪,补充医疗保险,定期体检,不加班,周末双休,试用期全额</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>5fe143d01766012a7d73fa34</td>\n",
       "      <td>在家作业/网上兼职/线上操作</td>\n",
       "      <td>中环汇峰环境科技(北京)有限公司</td>\n",
       "      <td>北京</td>\n",
       "      <td>8千-1万</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>其它</td>\n",
       "      <td>20人以下</td>\n",
       "      <td>技工/操作工</td>\n",
       "      <td>不限</td>\n",
       "      <td>五险一金,加班补助,全勤奖,绩效奖金</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        _id            职位名称              公司名称 工作城市   薪资范围  \\\n",
       "0  5fe143d01766012a7d73fa28  在家作业/网上兼职/线上操作  中环汇峰环境科技(北京)有限公司   北京  8千-1万   \n",
       "1  5fe143d01766012a7d73fa2b            送货司机  中融永信(北京)投资管理有限公司   北京  4千-6千   \n",
       "2  5fe143d01766012a7d73fa2e              警卫           美国驻华大使馆   北京  6千-8千   \n",
       "3  5fe143d01766012a7d73fa31       Bodyguard           美国驻华大使馆   北京  8千-1万   \n",
       "4  5fe143d01766012a7d73fa34  在家作业/网上兼职/线上操作  中环汇峰环境科技(北京)有限公司   北京  8千-1万   \n",
       "\n",
       "    学历要求  公司类型      公司规模        职位类别  工作经验  \\\n",
       "0  初中及以下    其它     20人以下      技工/操作工    不限   \n",
       "1  初中及以下    其它  500-999人      技工/操作工  1-3年   \n",
       "2  初中及以下  国家机关  100-299人    行政/后勤/文秘  1年以下   \n",
       "3  初中及以下  国家机关  100-299人  社区/居民/家政服务  3-5年   \n",
       "4  初中及以下    其它     20人以下      技工/操作工    不限   \n",
       "\n",
       "                                        福利待遇  \n",
       "0                         五险一金,加班补助,全勤奖,绩效奖金  \n",
       "1                       包吃,包住,节日福利,带薪年假,上六休一  \n",
       "2                             五险一金,加班补助,带薪年假  \n",
       "3  五险一金,带薪年假,年底双薪,补充医疗保险,定期体检,不加班,周末双休,试用期全额  \n",
       "4                         五险一金,加班补助,全勤奖,绩效奖金  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 删除id列并再次查看"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>职位名称</th>\n",
       "      <th>公司名称</th>\n",
       "      <th>工作城市</th>\n",
       "      <th>薪资范围</th>\n",
       "      <th>学历要求</th>\n",
       "      <th>公司类型</th>\n",
       "      <th>公司规模</th>\n",
       "      <th>职位类别</th>\n",
       "      <th>工作经验</th>\n",
       "      <th>福利待遇</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>在家作业/网上兼职/线上操作</td>\n",
       "      <td>中环汇峰环境科技(北京)有限公司</td>\n",
       "      <td>北京</td>\n",
       "      <td>8千-1万</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>其它</td>\n",
       "      <td>20人以下</td>\n",
       "      <td>技工/操作工</td>\n",
       "      <td>不限</td>\n",
       "      <td>五险一金,加班补助,全勤奖,绩效奖金</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>送货司机</td>\n",
       "      <td>中融永信(北京)投资管理有限公司</td>\n",
       "      <td>北京</td>\n",
       "      <td>4千-6千</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>其它</td>\n",
       "      <td>500-999人</td>\n",
       "      <td>技工/操作工</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>包吃,包住,节日福利,带薪年假,上六休一</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>警卫</td>\n",
       "      <td>美国驻华大使馆</td>\n",
       "      <td>北京</td>\n",
       "      <td>6千-8千</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>国家机关</td>\n",
       "      <td>100-299人</td>\n",
       "      <td>行政/后勤/文秘</td>\n",
       "      <td>1年以下</td>\n",
       "      <td>五险一金,加班补助,带薪年假</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>Bodyguard</td>\n",
       "      <td>美国驻华大使馆</td>\n",
       "      <td>北京</td>\n",
       "      <td>8千-1万</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>国家机关</td>\n",
       "      <td>100-299人</td>\n",
       "      <td>社区/居民/家政服务</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>五险一金,带薪年假,年底双薪,补充医疗保险,定期体检,不加班,周末双休,试用期全额</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>在家作业/网上兼职/线上操作</td>\n",
       "      <td>中环汇峰环境科技(北京)有限公司</td>\n",
       "      <td>北京</td>\n",
       "      <td>8千-1万</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>其它</td>\n",
       "      <td>20人以下</td>\n",
       "      <td>技工/操作工</td>\n",
       "      <td>不限</td>\n",
       "      <td>五险一金,加班补助,全勤奖,绩效奖金</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             职位名称              公司名称 工作城市   薪资范围   学历要求  公司类型      公司规模  \\\n",
       "0  在家作业/网上兼职/线上操作  中环汇峰环境科技(北京)有限公司   北京  8千-1万  初中及以下    其它     20人以下   \n",
       "1            送货司机  中融永信(北京)投资管理有限公司   北京  4千-6千  初中及以下    其它  500-999人   \n",
       "2              警卫           美国驻华大使馆   北京  6千-8千  初中及以下  国家机关  100-299人   \n",
       "3       Bodyguard           美国驻华大使馆   北京  8千-1万  初中及以下  国家机关  100-299人   \n",
       "4  在家作业/网上兼职/线上操作  中环汇峰环境科技(北京)有限公司   北京  8千-1万  初中及以下    其它     20人以下   \n",
       "\n",
       "         职位类别  工作经验                                       福利待遇  \n",
       "0      技工/操作工    不限                         五险一金,加班补助,全勤奖,绩效奖金  \n",
       "1      技工/操作工  1-3年                       包吃,包住,节日福利,带薪年假,上六休一  \n",
       "2    行政/后勤/文秘  1年以下                             五险一金,加班补助,带薪年假  \n",
       "3  社区/居民/家政服务  3-5年  五险一金,带薪年假,年底双薪,补充医疗保险,定期体检,不加班,周末双休,试用期全额  \n",
       "4      技工/操作工    不限                         五险一金,加班补助,全勤奖,绩效奖金  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del data['_id']\n",
    "data.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 查看数据集shape属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(302979, 10)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 对于重复公司的职位去重"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(116574, 10)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.drop_duplicates(subset=['公司名称','职位名称'],inplace=True)\n",
    "data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 统计空值，有则删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "职位名称    0\n",
       "公司名称    0\n",
       "工作城市    0\n",
       "薪资范围    0\n",
       "学历要求    0\n",
       "公司类型    0\n",
       "公司规模    0\n",
       "职位类别    0\n",
       "工作经验    0\n",
       "福利待遇    0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.isnull().sum()\n",
    "# data.dropna()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 统计工作经验发现有空格的存在"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1-3年     35629\n",
       "不限       33560\n",
       "3-5年     21384\n",
       "5-10年     9452\n",
       "无经验       6782\n",
       "          4292\n",
       "1年以下      3913\n",
       "10年以上     1562\n",
       "Name: 工作经验, dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['工作经验'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 先将空格转换为空值,再用dropna删除空值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['工作经验'].replace('', np.nan, inplace=True)\n",
    "data.dropna(subset=['工作经验'], inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 再次查看，确认空格已经删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1-3年     35629\n",
       "不限       33560\n",
       "3-5年     21384\n",
       "5-10年     9452\n",
       "无经验       6782\n",
       "1年以下      3913\n",
       "10年以上     1562\n",
       "Name: 工作经验, dtype: int64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['工作经验'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 查看面议字段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>职位名称</th>\n",
       "      <th>公司名称</th>\n",
       "      <th>工作城市</th>\n",
       "      <th>薪资范围</th>\n",
       "      <th>学历要求</th>\n",
       "      <th>公司类型</th>\n",
       "      <th>公司规模</th>\n",
       "      <th>职位类别</th>\n",
       "      <th>工作经验</th>\n",
       "      <th>福利待遇</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>28</td>\n",
       "      <td>正式员工-西餐厨师/(MUJI com北京京东店)</td>\n",
       "      <td>无印良品（上海）商业有限公司</td>\n",
       "      <td>北京</td>\n",
       "      <td>面议</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>外商独资</td>\n",
       "      <td>1000-9999人</td>\n",
       "      <td>烹饪/料理/食品研发</td>\n",
       "      <td>无经验</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>72</td>\n",
       "      <td>饮水机维修员</td>\n",
       "      <td>广州屈臣氏食品饮料有限公司</td>\n",
       "      <td>北京</td>\n",
       "      <td>面议</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>合资</td>\n",
       "      <td>1000-9999人</td>\n",
       "      <td>电子/电器/半导体/仪器仪表</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>五险一金,年底双薪,带薪年假,补充医疗保险,定期体检,免费班车,交通补助</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>668</td>\n",
       "      <td>央企诚聘帮厨（包食宿）</td>\n",
       "      <td>中冶置业集团</td>\n",
       "      <td>北京</td>\n",
       "      <td>面议</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>国企</td>\n",
       "      <td>500-999人</td>\n",
       "      <td>烹饪/料理/食品研发</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>定期体检,带薪年假,包吃,包住,交通补助,弹性工作</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2409</td>\n",
       "      <td>店员/营业员</td>\n",
       "      <td>美团（中国大陆地区）</td>\n",
       "      <td>北京</td>\n",
       "      <td>面议</td>\n",
       "      <td>高中</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>10000人以上</td>\n",
       "      <td>商超/酒店/娱乐管理/服务</td>\n",
       "      <td>不限</td>\n",
       "      <td>绩效奖金</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2494</td>\n",
       "      <td>弱电维修工</td>\n",
       "      <td>远洋集团</td>\n",
       "      <td>北京</td>\n",
       "      <td>面议</td>\n",
       "      <td>高中</td>\n",
       "      <td>上市公司</td>\n",
       "      <td>10000人以上</td>\n",
       "      <td>土木/建筑/装修/市政工程</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>五险一金,绩效奖金,带薪年假,包住,餐补,通讯补助</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           职位名称            公司名称 工作城市 薪资范围   学历要求  公司类型  \\\n",
       "28    正式员工-西餐厨师/(MUJI com北京京东店)  无印良品（上海）商业有限公司   北京   面议  初中及以下  外商独资   \n",
       "72                       饮水机维修员   广州屈臣氏食品饮料有限公司   北京   面议  初中及以下    合资   \n",
       "668                 央企诚聘帮厨（包食宿）          中冶置业集团   北京   面议  初中及以下    国企   \n",
       "2409                     店员/营业员      美团（中国大陆地区）   北京   面议     高中  上市公司   \n",
       "2494                      弱电维修工            远洋集团   北京   面议     高中  上市公司   \n",
       "\n",
       "            公司规模            职位类别  工作经验                                  福利待遇  \n",
       "28    1000-9999人      烹饪/料理/食品研发   无经验                                        \n",
       "72    1000-9999人  电子/电器/半导体/仪器仪表  1-3年  五险一金,年底双薪,带薪年假,补充医疗保险,定期体检,免费班车,交通补助  \n",
       "668     500-999人      烹饪/料理/食品研发  1-3年             定期体检,带薪年假,包吃,包住,交通补助,弹性工作  \n",
       "2409    10000人以上   商超/酒店/娱乐管理/服务    不限                                  绩效奖金  \n",
       "2494    10000人以上   土木/建筑/装修/市政工程  1-3年             五险一金,绩效奖金,带薪年假,包住,餐补,通讯补助  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp = data[data['薪资范围'].isin(['面议'])]\n",
    "temp.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 反选出非面议字段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = data[~data['薪资范围'].isin(['面议'])] "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 查看薪资范围"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "千    68007\n",
      "万    21725\n",
      ".    19016\n",
      "0      121\n",
      "2        1\n",
      "Name: 薪资范围, dtype: int64\n",
      "------------------------------\n",
      "万    62956\n",
      "千    45749\n",
      "下      157\n",
      "上        8\n",
      "Name: 薪资范围, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(df['薪资范围'].str[1].value_counts())\n",
    "print('-'*30)\n",
    "print(df['薪资范围'].str[-1].value_counts())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 利用正则表达式提取薪资数据，剔除千、万"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0             8千-1万\n",
       "1             4千-6千\n",
       "2             6千-8千\n",
       "3             8千-1万\n",
       "6           1万-1.5万\n",
       "            ...    \n",
       "302963    1.2万-2.4万\n",
       "302964        3万-5万\n",
       "302965         1千以下\n",
       "302966      2.5万-5万\n",
       "302978      2.5万-3万\n",
       "Name: 薪资范围, Length: 108870, dtype: object"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['薪资范围']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0              [8000, 10000]\n",
       "1               [4000, 6000]\n",
       "2               [6000, 8000]\n",
       "3              [8000, 10000]\n",
       "6           [10000, 15000.0]\n",
       "                 ...        \n",
       "302963    [12000.0, 24000.0]\n",
       "302964        [30000, 50000]\n",
       "302965                [1000]\n",
       "302966      [25000.0, 50000]\n",
       "302978      [25000.0, 30000]\n",
       "Name: 薪资范围, Length: 108870, dtype: object"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ptn = re.compile(r'\\d+(\\.\\d+)?(千|万)')\n",
    "def split_money(x):\n",
    "    return [eval(i.group().replace('千','*1000').replace('万','*10000')) for i in ptn.finditer(x)]\n",
    "\n",
    "                    \n",
    "salary = df['薪资范围'].apply(split_money)\n",
    "salary"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 在原数据中添加最大、最小、平均薪水三列，平均薪水是用mean方法得到"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          9000\n",
       "1          5000\n",
       "2          7000\n",
       "3          9000\n",
       "6         12500\n",
       "          ...  \n",
       "302963    18000\n",
       "302964    40000\n",
       "302965      500\n",
       "302966    37500\n",
       "302978    27500\n",
       "Name: salary_mean, Length: 108870, dtype: int32"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.copy()\n",
    "df.loc[:,'salary_min'] = salary.str[0].fillna(0).astype('int')\n",
    "df.loc[:,'salary_max'] = salary.str[1].fillna(0).astype('int')\n",
    "df.loc[:,'salary_mean'] = df[['salary_min','salary_max']].mean(axis=1).astype('int')\n",
    "df['salary_mean']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 公司人员重构，去除数据中原有格式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100-299      28201\n",
       "1000-9999    27252\n",
       "20-99        21871\n",
       "大于10000      15359\n",
       "500-999      12807\n",
       "少于20          3640\n",
       "300-499       2500\n",
       "Name: 公司规模, dtype: int64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def clean_people(x):\n",
    "    if x == '20-99人':\n",
    "        return \"20-99\"\n",
    "    elif x == '100-299人':\n",
    "        return \"100-299\"\n",
    "    elif x == '300-499人':\n",
    "        return \"300-499\"\n",
    "    elif x == '500-999人':\n",
    "        return \"500-999\"\n",
    "    elif x == '1000-9999人':\n",
    "        return \"1000-9999\"\n",
    "    elif x == '10000人以上':\n",
    "        return \"大于10000\"\n",
    "    elif x == '20人以下':\n",
    "        return \"少于20\"\n",
    "    else:\n",
    "        return np.nan\n",
    "         \n",
    "data['公司规模'] = data['公司规模'].apply(clean_people)\n",
    "data['公司规模'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 数据清洗工作到这一步已经完成的差不多了，现在重组一下数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>工作</th>\n",
       "      <th>公司</th>\n",
       "      <th>工作城市</th>\n",
       "      <th>薪水</th>\n",
       "      <th>学历</th>\n",
       "      <th>最低薪</th>\n",
       "      <th>最高薪</th>\n",
       "      <th>平均薪</th>\n",
       "      <th>公司规模</th>\n",
       "      <th>公司类型</th>\n",
       "      <th>职位类别</th>\n",
       "      <th>工作经验</th>\n",
       "      <th>福利待遇</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>在家作业/网上兼职/线上操作</td>\n",
       "      <td>中环汇峰环境科技(北京)有限公司</td>\n",
       "      <td>北京</td>\n",
       "      <td>8千-1万</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>8000</td>\n",
       "      <td>10000</td>\n",
       "      <td>9000</td>\n",
       "      <td>20人以下</td>\n",
       "      <td>其它</td>\n",
       "      <td>技工/操作工</td>\n",
       "      <td>不限</td>\n",
       "      <td>五险一金,加班补助,全勤奖,绩效奖金</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>送货司机</td>\n",
       "      <td>中融永信(北京)投资管理有限公司</td>\n",
       "      <td>北京</td>\n",
       "      <td>4千-6千</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>4000</td>\n",
       "      <td>6000</td>\n",
       "      <td>5000</td>\n",
       "      <td>500-999人</td>\n",
       "      <td>其它</td>\n",
       "      <td>技工/操作工</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>包吃,包住,节日福利,带薪年假,上六休一</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>警卫</td>\n",
       "      <td>美国驻华大使馆</td>\n",
       "      <td>北京</td>\n",
       "      <td>6千-8千</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>6000</td>\n",
       "      <td>8000</td>\n",
       "      <td>7000</td>\n",
       "      <td>100-299人</td>\n",
       "      <td>国家机关</td>\n",
       "      <td>行政/后勤/文秘</td>\n",
       "      <td>1年以下</td>\n",
       "      <td>五险一金,加班补助,带薪年假</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>Bodyguard</td>\n",
       "      <td>美国驻华大使馆</td>\n",
       "      <td>北京</td>\n",
       "      <td>8千-1万</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>8000</td>\n",
       "      <td>10000</td>\n",
       "      <td>9000</td>\n",
       "      <td>100-299人</td>\n",
       "      <td>国家机关</td>\n",
       "      <td>社区/居民/家政服务</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>五险一金,带薪年假,年底双薪,补充医疗保险,定期体检,不加班,周末双休,试用期全额</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>Bodyguard Shift Leader</td>\n",
       "      <td>美国驻华大使馆</td>\n",
       "      <td>北京</td>\n",
       "      <td>1万-1.5万</td>\n",
       "      <td>初中及以下</td>\n",
       "      <td>10000</td>\n",
       "      <td>15000</td>\n",
       "      <td>12500</td>\n",
       "      <td>100-299人</td>\n",
       "      <td>国家机关</td>\n",
       "      <td>社区/居民/家政服务</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>五险一金,带薪年假,年底双薪,补充医疗保险,定期体检,不加班,周末双休,试用期全额</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       工作                公司 工作城市       薪水     学历    最低薪  \\\n",
       "0          在家作业/网上兼职/线上操作  中环汇峰环境科技(北京)有限公司   北京    8千-1万  初中及以下   8000   \n",
       "1                    送货司机  中融永信(北京)投资管理有限公司   北京    4千-6千  初中及以下   4000   \n",
       "2                      警卫           美国驻华大使馆   北京    6千-8千  初中及以下   6000   \n",
       "3               Bodyguard           美国驻华大使馆   北京    8千-1万  初中及以下   8000   \n",
       "6  Bodyguard Shift Leader           美国驻华大使馆   北京  1万-1.5万  初中及以下  10000   \n",
       "\n",
       "     最高薪    平均薪      公司规模  公司类型        职位类别  工作经验  \\\n",
       "0  10000   9000     20人以下    其它      技工/操作工    不限   \n",
       "1   6000   5000  500-999人    其它      技工/操作工  1-3年   \n",
       "2   8000   7000  100-299人  国家机关    行政/后勤/文秘  1年以下   \n",
       "3  10000   9000  100-299人  国家机关  社区/居民/家政服务  3-5年   \n",
       "6  15000  12500  100-299人  国家机关  社区/居民/家政服务  3-5年   \n",
       "\n",
       "                                        福利待遇  \n",
       "0                         五险一金,加班补助,全勤奖,绩效奖金  \n",
       "1                       包吃,包住,节日福利,带薪年假,上六休一  \n",
       "2                             五险一金,加班补助,带薪年假  \n",
       "3  五险一金,带薪年假,年底双薪,补充医疗保险,定期体检,不加班,周末双休,试用期全额  \n",
       "6  五险一金,带薪年假,年底双薪,补充医疗保险,定期体检,不加班,周末双休,试用期全额  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df[['职位名称','公司名称','工作城市','薪资范围','学历要求','salary_min','salary_max',\n",
    "                   'salary_mean','公司规模','公司类型','职位类别','工作经验','福利待遇']]\n",
    "df.columns=['工作','公司','工作城市','薪水','学历','最低薪','最高薪',\n",
    "                '平均薪','公司规模','公司类型','职位类别','工作经验','福利待遇']\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 企业性质占比\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'E:\\\\crawler\\\\Scrapy\\\\ZhiLian\\\\ZhiLian\\\\spiders\\\\企业性质占比.html'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def pie_rosetype(col) -> Pie:\n",
    "    c = (\n",
    "        Pie(init_opts=opts.InitOpts(theme=ThemeType.CHALK))\n",
    "        .add(\n",
    "            \"\",\n",
    "            [list(z) for z in zip(col.index.tolist(), \n",
    "                                  col.values.tolist())],\n",
    "            radius=[\"30%\", \"75%\"],\n",
    "            center=[\"50%\", \"50%\"],\n",
    "            rosetype=\"radius\",\n",
    "            label_opts=opts.LabelOpts(is_show=False),\n",
    "        )\n",
    "\n",
    "        .set_global_opts(title_opts=opts.TitleOpts(title=\"企业性质占比\"),\n",
    "                        legend_opts=opts.LegendOpts(\n",
    "                        orient=\"vertical\", pos_top=\"20%\", pos_left=\"0.5%\"))\n",
    "        .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}: {c}\"))\n",
    "    )\n",
    "    return c\n",
    "pie_rosetype(df['公司类型'].value_counts()).render(\"企业性质占比.html\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 企业规模分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'E:\\\\crawler\\\\Scrapy\\\\ZhiLian\\\\ZhiLian\\\\spiders\\\\企业规模分布.html'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.commons.utils import JsCode\n",
    "c = (\n",
    "    Bar(init_opts=opts.InitOpts(width=\"1500px\",theme=ThemeType.WONDERLAND))\n",
    "    .add_xaxis(df['公司规模'].value_counts().index.tolist())\n",
    "    .add_yaxis(\"企业数\", df['公司规模'].value_counts().values.tolist(), category_gap=\"60%\")\n",
    "    .set_series_opts(itemstyle_opts={\n",
    "        \"normal\": {\n",
    "            \"color\": JsCode(\"\"\"new echarts.graphic.LinearGradient(0, 0, 0, 1, [{\n",
    "                offset: 0,\n",
    "                color: 'rgba(0, 244, 255, 1)'\n",
    "            }, {\n",
    "                offset: 1,\n",
    "                color: 'rgba(0, 77, 167, 1)'\n",
    "            }], false)\"\"\"),\n",
    "            \"barBorderRadius\": [30, 30, 30, 30],\n",
    "            \"shadowColor\": 'rgb(0, 160, 221)',\n",
    "        }})\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"企业规模分布\"),\n",
    "                     xaxis_opts=opts.AxisOpts(name=\"企业人数区间\")))\n",
    "c.render(\"企业规模分布.html\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 企业性质薪水对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'E:\\\\crawler\\\\Scrapy\\\\ZhiLian\\\\ZhiLian\\\\spiders\\\\企业性质薪水对比.html'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gp_job_money = df.groupby('公司类型')['平均薪'].mean()\n",
    "company = gp_job_money.astype(int).sort_values(ascending=False)\n",
    "\"\"\"柱状图\"\"\"\n",
    "bar = (Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))\n",
    "            .add_xaxis(company.index.tolist())\n",
    "            .add_yaxis(\"\",company.values.tolist() )\n",
    "            .set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"企业性质薪水对比\"),\n",
    "            datazoom_opts=opts.DataZoomOpts(type_=\"inside\"),\n",
    "            yaxis_opts=opts.AxisOpts(name=\"薪水\"),\n",
    "            xaxis_opts=opts.AxisOpts(name=\"\",axislabel_opts={\"rotate\":30})\n",
    "        )\n",
    "    )\n",
    "bar.render(\"企业性质薪水对比.html\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 热门城市工作数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'E:\\\\crawler\\\\Scrapy\\\\ZhiLian\\\\ZhiLian\\\\spiders\\\\热门城市工作数量.html'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city = df.loc[df['工作城市']!='异地招聘',:]['工作城市'].value_counts()[:10].index\n",
    "number = df.loc[df['工作城市']!='异地招聘',:]['工作城市'].value_counts()[:10].values\n",
    "\n",
    "pie = (\n",
    "    Pie(init_opts=opts.InitOpts(theme=ThemeType.WONDERLAND))\n",
    "    .add(\n",
    "        \"\",\n",
    "        [list(z) for z in zip(city.tolist(), \n",
    "                              number.tolist())],\n",
    "        radius=[\"40%\", \"75%\"],\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"热门城市工作数量\"),\n",
    "        legend_opts=opts.LegendOpts(\n",
    "            orient=\"vertical\", pos_top=\"15%\", pos_left=\"2%\"\n",
    "        ),\n",
    "    )\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}: {c}\"))\n",
    ")\n",
    "pie.render(\"热门城市工作数量.html\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 薪水与学历走势"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'E:\\\\crawler\\\\Scrapy\\\\ZhiLian\\\\ZhiLian\\\\spiders\\\\薪水与学历走势.html'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "edu_m_pivot = df.pivot_table(index=\"学历\",\n",
    "                                 values = ['平均薪'],\n",
    "                                 aggfunc = {'平均薪':'mean','学历':'count'})\n",
    "edu_m_pivot.columns = ['公司规模','平均薪']\n",
    "edu_m_pivot = edu_m_pivot.sort_values(by=['平均薪'],ascending=False)\n",
    "\n",
    "\n",
    "grid = Grid()\n",
    "bar = Bar()\n",
    "grid.theme = ThemeType.PURPLE_PASSION\n",
    "line = Line()\n",
    "\n",
    "\n",
    "bar.add_xaxis(edu_m_pivot.index.tolist())\n",
    "bar.add_yaxis(\"学历\",edu_m_pivot['公司规模'].tolist(),\n",
    "              label_opts=opts.LabelOpts(is_show=True))\n",
    "\n",
    "bar.extend_axis(yaxis=opts.AxisOpts(type_=\"value\",\n",
    "                                     name=\"薪水\",\n",
    "                                     position=\"right\",                    \n",
    "                                     axislabel_opts=opts.LabelOpts(formatter=\"{value}元\"),\n",
    "                                     ))\n",
    "\n",
    "bar.set_global_opts(yaxis_opts=opts.AxisOpts(\n",
    "                                            name=\"学历人数\",\n",
    "                                            type_=\"value\",\n",
    "                                            axislabel_opts=opts.LabelOpts(formatter=\"{value}人\")\n",
    "                                            ), \n",
    "                    title_opts=opts.TitleOpts(\"薪水与学历走势\"),\n",
    "                    tooltip_opts=opts.TooltipOpts(trigger=\"axis\", axis_pointer_type=\"cross\"),\n",
    "                   ) \n",
    "\n",
    "line.add_xaxis(edu_m_pivot.index.tolist())\n",
    "line.add_yaxis(\"平均薪水\",edu_m_pivot['平均薪'].astype('int').tolist(),yaxis_index = 1,label_opts=opts.LabelOpts(is_show=False))\n",
    "\n",
    "# 把line添加到bar上\n",
    "bar.overlap(line)\n",
    "grid.add(chart = bar,grid_opts = opts.GridOpts(),is_control_axis_index = True)\n",
    "grid.render(\"薪水与学历走势.html\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 薪水与工作经验走势"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'E:\\\\crawler\\\\Scrapy\\\\ZhiLian\\\\ZhiLian\\\\spiders\\\\薪水与工作经验走势.html'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "jy_m_pivot = df.pivot_table(index=\"工作经验\",\n",
    "                                 values = ['平均薪'],\n",
    "                                 aggfunc = {'平均薪':'mean','工作经验':'count'})\n",
    "jy_m_pivot.columns = ['公司规模','平均薪']\n",
    "jy_m_pivot = jy_m_pivot.sort_values(by=['平均薪'],ascending=False)\n",
    "\n",
    "\n",
    "grid = Grid()\n",
    "bar = Bar()\n",
    "grid.theme = ThemeType.DARK \n",
    "line = Line()\n",
    "\n",
    "\n",
    "bar.add_xaxis(jy_m_pivot.index.tolist())\n",
    "bar.add_yaxis(\"工作经验\",jy_m_pivot['公司规模'].tolist(),\n",
    "              label_opts=opts.LabelOpts(is_show=True))\n",
    "\n",
    "bar.extend_axis(yaxis=opts.AxisOpts(type_=\"value\",\n",
    "                                     name=\"薪水\",\n",
    "                                     position=\"right\",\n",
    "                                     axislabel_opts=opts.LabelOpts(formatter=\"{value}元\"),\n",
    "                                     ))\n",
    "\n",
    "bar.set_global_opts(yaxis_opts=opts.AxisOpts(\n",
    "                                            name=\"经验人数\",\n",
    "                                            type_=\"value\",\n",
    "                                            axislabel_opts=opts.LabelOpts(formatter=\"{value}人\")\n",
    "                                            ),\n",
    "                    title_opts=opts.TitleOpts(\"薪水与工作经验走势\"),\n",
    "                    tooltip_opts=opts.TooltipOpts(trigger=\"axis\", axis_pointer_type=\"cross\"),\n",
    "                   ) # 交叉指向工具\n",
    "\n",
    "line.add_xaxis(jy_m_pivot.index.tolist())\n",
    "line.add_yaxis(\"平均薪水\",jy_m_pivot['平均薪'].astype('int').tolist(),yaxis_index = 1,label_opts=opts.LabelOpts(is_show=False))\n",
    "\n",
    "# 把line添加到bar上\n",
    "bar.overlap(line)\n",
    "grid.add(chart = bar,grid_opts = opts.GridOpts(),is_control_axis_index = True)\n",
    "grid.render('薪水与工作经验走势.html')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 平均薪水区间分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'E:\\\\crawler\\\\Scrapy\\\\ZhiLian\\\\ZhiLian\\\\spiders\\\\平均薪水区间分布.html'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# 设置切分区域\n",
    "listBins = [0,1000,5000,7000,8000,9000,10000,12000,15000,18000,20000,5000000]\n",
    "# 设置切分后对应标签\n",
    "listLabels = ['1000以下','1000-5000', '5000-7000','7000-8000','8000-9000',\n",
    "              '9000-10000','10000-12000','12000-15000', '15000-18000',\n",
    "              '18000-20000','20000以上']\n",
    "# 分区统计\n",
    "time_count_list = pd.cut(df['平均薪'].sort_values(),bins=listBins,labels=listLabels,include_lowest=True)\n",
    "time_count_list\n",
    "time_count_dict = {i:0 for i in time_count_list}\n",
    "time_count_dict\n",
    "for i in time_count_list:\n",
    "    time_count_dict[i] = time_count_dict.get(i)+1\n",
    "time_count_dict \n",
    "\n",
    "\"\"\"柱状图\"\"\"\n",
    "bar = (Bar(init_opts=opts.InitOpts(theme=ThemeType.VINTAGE))\n",
    "            .add_xaxis(list(time_count_dict.keys()))\n",
    "            .add_yaxis(\"\", list(time_count_dict.values()))\n",
    "            .set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"平均薪水区间分布\"),\n",
    "            yaxis_opts=opts.AxisOpts(name=\"人数\"),\n",
    "            xaxis_opts=opts.AxisOpts(name=\"薪水区间\",axislabel_opts={\"rotate\":30})\n",
    "        )\n",
    "    )\n",
    "bar.render(\"平均薪水区间分布.html\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 福利待遇词云图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'E:\\\\crawler\\\\Scrapy\\\\ZhiLian\\\\ZhiLian\\\\spiders\\\\福利待遇词云图.html'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job_list = data['福利待遇'].tolist()\n",
    "title_list = []\n",
    "for i in job_list:\n",
    "    try:\n",
    "        for a in i:\n",
    "            title_list.append(a)\n",
    "    except Exception as a:\n",
    "        pass\n",
    "    \n",
    "title_ = np.array(title_list[:10000])\n",
    "\n",
    "\n",
    "tag_list=','.join(title_).split(',')\n",
    "tags_count=pd.Series(tag_list).value_counts()\n",
    "\n",
    "wordcloud = (\n",
    "    WordCloud()\n",
    "    .add(\"\",\n",
    "         [list(z) for z in zip(tags_count.index,tags_count)], \n",
    "         word_size_range=[50, 200])\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"福利待遇\",title_textstyle_opts=opts.TextStyleOpts(font_size=40)))\n",
    ")\n",
    "wordcloud.render(\"福利待遇词云图.html\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 按平均薪水统计出排名前10的工作岗位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "137374    法务总经理-金融行业-上海/北京\n",
       "67285               政府事务总监\n",
       "298596         财务副总裁（地产方向）\n",
       "45366              兼职平面设计师\n",
       "285252           销售经理（合伙人）\n",
       "78280           CEO/总裁/总经理\n",
       "67066              人力资源副总裁\n",
       "243374       置业顾问/低薪七千起/包住\n",
       "296136        华中区域副总裁（投融资）\n",
       "77621             实验室首席科学家\n",
       "Name: 工作, dtype: object"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job = df.sort_values(by=['平均薪'],ascending=False).head(10)\n",
    "top_job = job['工作'].head(10)\n",
    "top_job"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 统计出排名前10的平均薪水"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "137374    137500\n",
       "67285     125000\n",
       "298596    125000\n",
       "45366     125000\n",
       "285252    125000\n",
       "78280     125000\n",
       "67066     125000\n",
       "243374    125000\n",
       "296136    125000\n",
       "77621     125000\n",
       "Name: 平均薪, dtype: int32"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "top_money = job['平均薪'].head(10)\n",
    "top_money"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 根据统计结果绘制Top10岗位平均薪水图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'E:\\\\crawler\\\\Scrapy\\\\ZhiLian\\\\ZhiLian\\\\spiders\\\\Top10岗位平均薪水.html'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar = (Bar(init_opts=opts.InitOpts(width=\"1500px\",theme=ThemeType.WONDERLAND))\n",
    "            .add_xaxis(top_job.tolist())\n",
    "            .add_yaxis(\"\",top_money.tolist() )\n",
    "            .set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"Top10岗位平均薪水\"),\n",
    "            yaxis_opts=opts.AxisOpts(name=\"工资\"),\n",
    "            xaxis_opts=opts.AxisOpts(name=\"工作\",axislabel_opts={\"interval\":\"0\",\"rotate\":12})\n",
    "        )\n",
    "    )\n",
    "bar.render(\"Top10岗位平均薪水.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
